<?php

namespace App\Http\Controllers\Api;

use App\Http\Services\Manage\ExportService;
use App\Models\ComboSpecItem;
use App\Models\Printer;
use App\Models\ProductComboMapping;
use App\Models\SpecItem;
use App\Models\Supplier;
use App\Models\Wemch;
use App\Repositories\Api\DailyMenuRepository;
use App\Repositories\Api\MemberRepository;
use App\Repositories\Api\ProductRepository;
use App\Repositories\Api\ShopRepository;
use App\Repositories\Api\SupplierRepository;
use App\Repositories\OrderRepository;
use App\Repositories\PrinterRepository;
use App\Repositories\WechatRepository;
use Exception;
use Illuminate\Support\Facades\DB;

class OrderController extends MiniAppController
{
    private $memberRep = NULL,
        $orderRep = NULL;

    public function __construct(
        MemberRepository $memberRep,
        OrderRepository  $orderRep
    )
    {
        parent::__construct();

        $this->memberRep = $memberRep;
        $this->orderRep = $orderRep;
    }

    public function index()
    {
        $filter['uid'] = UID;
        $status = intval(request()->get("status"));

        switch ($status) {
            case 4:
                $filter['status'] = [20, 60, 80];
                break;
            case 3://配送中
                $filter['status'] = 10;
                $filter['delivery_status'] = 20;
                $filter['deliver_status'] = 3;
                break;
            case 2:
                $filter['status'] = 10;
                $filter['delivery_status'] = 10;
//                $filter['deliver_status'] = 0;
                break;
            case 1:
                $filter['status'] = 1;
                break;

            default:
                break;
        }

        $res = $this->orderRep->getLists($filter, $this->pageNum, $this->pageSize);
        return retSuc($res);
    }

    /**
     * 生成订单
     */
    public function create()
    {
        $type = request()->post("type");
        if (!in_array($type, ['buyer', 'buyer1'])) {
            return retFail("订单类型不存在");
        }

        file_put_contents("/tmp/check_qrcode_ablumn.txt", $type . "4" . "\n", 8);
        $total_amount = 0;
        $shop_id = intval(request()->post("shop_id"));

        $shop = (new ShopRepository())->getOne($shop_id);
        if (empty($shop))
            return retFail("店铺不存在");

        /*if ($shop['is_open'] != 1)
            return retFail("店铺已打烊，明天早点来哟！");
        */

        $products = request()->post("products");
        $delivery_time = request()->get("delivery_time");
        switch ($type) {
            case "buyer1"://注销账户余额不足 支付
                $address_id = request()->post("address_id");
                if (empty($address_id))
                    return retFail("收货地址必填");
                $productRep = (new ProductRepository());
                $comboData = request()->post("comboData");
                $productData = request()->post("products");

                //套餐
                $goodsList = [];
                $total_price = 0.0;
                $amount = 0;
                foreach ($comboData as $k => $combo) {
//                    $amount += 1;
                    $total_amount += intval($combo['amount']);
                    $g = [];
                    $g['product_sku_id'] = $combo['id'] ?? 0;
                    $g['uid'] = UID;
                    $g['product_price'] = $combo['price'] ?? 0.0;
                    $g['combo_amount'] = $combo['amount'] ?? 1;
                    $g['combo_sort'] = $combo['sort'] ?? 0;
                    $g['create_time'] = $g['update_time'] = date("Y-m-d H:i:s");

                    foreach ($combo['products'] as $pk => $product) {
                        if ($product['amount'] <= 0) continue;
                        $current_product = $productRep->getOne($product['id']);
                        $g['product_id'] = $product['id'];
                        $g['stall_id'] = $current_product['shop_id'] ?? 0;
                        $g['amount'] = $product['amount'];
                        $g['thumb'] = $current_product['thumb'] ?? "";
                        $g['sequence'] = ProductComboMapping::getSeqence($combo['id'], $product['id']);

                        $goodsList[] = $g;
                    }
                    $total_price += floatval($g['product_price']) * intval($g['combo_amount']);
                }

                //套餐 商品
                foreach ($productData as $k => $product) {
                    $total_amount += $product['amount'];
                    $current_product = $productRep->getOne($product['id']);
                    $g = [];
                    $g['product_sku_id'] = 0;
                    $g['uid'] = UID;
                    $g['product_price'] = round($current_product['price'], 2);
                    $g['create_time'] = $g['update_time'] = date("Y-m-d H:i:s");
                    $g['product_id'] = $product['id'];
                    $g['amount'] = $product['amount'];
                    $g['combo_amount'] = 1; //套餐数量
                    $g['combo_sort'] = 0; //套餐序号
                    $g['sequence'] = 1;
                    $g['thumb'] = $current_product['thumb'] ?? "";
                    $g['stall_id'] = $current_product['stall_id'] ?? 0;
                    $goodsList[] = $g;

                    $amount += 1;
                    $total_price += floatval($g['product_price']) * intval($g['amount']);
                }

                $data['total_price'] = round($total_price, 2);
                $data['type'] = 1; // 账号付费恢复
                $data['refund_price'] = 0.00;
                $data['goodsList'] = $goodsList;
                $data['menu_id'] = request()->post("menu_id") ?? 0;
                $data['menu_type'] = $menu['type'] ?? 0;
                $data['amount'] = $total_amount;
                $data['buyer_remark'] = request()->post("remark", "");
                $data['order_source'] = intval(request()->post("order_source", 0));
                // $data['total_price'] = 0.01;
                break;

            case "buyer":
                $address_id = request()->post("address_id");
                $menu_id = intval(request()->post("menu_id"));
                if (empty($address_id))
                    return retFail("收货地址必填");

                if ($shop['type'] == 0 && empty($delivery_time)) {
                    return retFail("请选择配送时间");
                }

                $menu = (new DailyMenuRepository())->getOne($menu_id);
                if (!isset($menu))
                    return retFail("菜单不存在，请刷新再试");
                if ($menu['status'] !== 1) {
                    return retFail("菜单已下架");
                }

                if (empty($menu) || $menu['is_order'] == 0) {
                    return retFail("菜单不存在，请刷新再试");
                } else if ($menu['is_order'] == 2) {
                    if ($shop['type'] != 1) {
                        return retFail("店铺已打烊，明天早点来哟！");
                    }
                    return retFail("菜单未开始订餐");
                }

                $shop_id = $shop_id > 0 ? $shop_id : $menu['shop_id'];
                $productRep = (new ProductRepository());
                $productData = request()->post("products");

                //套餐数据
                $total_price = 0.0;
                $amount = 0;
                $bag_price = 0;

                //套餐 商品
                $goodsList = [];
                $sql = "";
                foreach ($productData as $k => $product) {
                    $total_amount += $product['amount'];
                    $current_product = $productRep->getOne($product['id']);

                    if ($current_product['stock'] <= 0) {
                        return retFail("库存不足");
                    }

                    //减库存
                    $sql .= "update wx_product set `stock`=`stock`-" . (intval($product['amount'] ?? 1)) . " where id={$product['id']};";

                    $product_bag_price = floatval($current_product['bag_price'] ?? 0) * intval($product['amount'] ?? 1);
                    $bag_price += $product_bag_price;

                    $g = [];
                    $g['uid'] = UID;
                    $g['type'] = 0;
                    $g['product_price'] = round($current_product['price'], 1);
                    $g['product_title'] = $current_product['title'];
                    $g['bag_price'] = floatval($current_product['bag_price'] ?? 0); //商品打包费
                    $g['create_time'] = $g['update_time'] = date("Y-m-d H:i:s");
                    $g['product_id'] = $product['id'];
                    $g['amount'] = $product['amount'];
                    $g['thumb'] = $current_product['thumb'];
                    $g['stall_id'] = $current_product['stall_id'] ?? 0;
                    $g['shop_id'] = $shop_id;
                    $g['combo_amount'] = 1; //套餐数量
                    $g['combo_sort'] = 0; //套餐序号

                    $skus = [];
                    if ($current_product['product_type'] == 1) { // 套餐
                        $g['type'] = 1; // 商品类型 (0: 普通 1：套餐 2:多规格)

                        foreach ($product['skus'] as $sk => $sv) {
                            $specItem = ComboSpecItem::query()->where(['id' => $sv['id']])->first();
                            if (!isset($specItem)) continue;
                            $skus[] = [
                                "goods_id" => $product['id'],
                                "spec_id" => $specItem['spec_id'],
                                "spec_item_id" => $specItem['id'],
                                "spec_item_title" => $specItem['title'],
                                "amount" => $sv['amount'] ?? 1,
                                "type" => 1,
                                "sequence" => $specItem['sn'],
                                "create_time" => date("Y-m-d H:i:s")
                            ];
                        }
                        $g['skus'] = $skus;
                    } else {
                        if (!empty($product['skus']) && count($product['skus']) > 0) {
                            $g['type'] = 2;
                            foreach ($product['skus'] as $sk => $sv) {
                                $specItem = SpecItem::query()->where(['id' => $sv['id']])->first();
                                if (!isset($specItem)) continue;
                                $skus[] = [
                                    "goods_id" => $product['id'],
                                    "amount" => $sv['amount'] ?? 1,
                                    "spec_id" => $specItem['spec_id'],
                                    "spec_item_id" => $specItem['id'],
                                    "spec_item_title" => $specItem['title'],
                                    "spec_price" => $specItem['price'] ?? 0,
                                    "create_time" => date("Y-m-d H:i:s")
                                ];
                                $g['product_price'] += floatval($specItem['price']);
                            }

                            $g['skus'] = $skus;
                        }
                    }

                    $goodsList[] = $g;
                    $amount += 1;
                    $total_price += floatval($g['product_price']) * intval($g['amount']);
                }

                $cal_shipping_price = (new SupplierRepository())->calShippingPrice($total_amount, $shop['base_shipping_price']);
                $data['total_price'] = formatNum($total_price + $cal_shipping_price) + formatNum($bag_price);
                $data['bag_price'] = formatNum($bag_price);
                $data['express_price'] = formatNum($cal_shipping_price); //配送金额
                $data['type'] = 1; // 账号付费恢复
                $data['refund_price'] = 0.00;
                $data['goodsList'] = $goodsList ?? [];
                $data['menu_id'] = $menu_id ?? 0;
                $data['menu_type'] = $menu['type'] ?? 0;
                $data['amount'] = $total_amount;
                $data['buyer_remark'] = request()->post("remark", "");
                $data['mealtime'] = $menu['menu_type'] == 1 ? $menu['deliver_time'] : '';
                $data['delivery_date'] = $menu['date'] ?? "";
                $data['order_source'] = intval(request()->post("order_source", 0));

                $delivery_time = explode(' ', $delivery_time);
                if (count($delivery_time) == 2) { //配送时间
                    $data['delivery_date'] = $delivery_time[0];
                    $times = explode('-', $delivery_time[1]);
                    $data['delivery_start_time'] = $times[0];
                    $data['delivery_end_time'] = $times[1];
                }

                break;
            default:
                break;
        }

        if (env("APP_DEBUG") || UID == 1) {
            $data['total_price'] = 0.01;
        }

        if (empty($data))
            return retFail("订单数据异常");

        $data['shop_id'] = $shop_id;
        if ($data['order_source'] == 1) { //代下单直接付款成功
            $data['status'] = 10;
        }
        $data['shop_type'] = intval($shop['type']);
        $order = $this->orderRep->generateOrder($data);

        //下单减库存
        if ($order && intval($shop['stock_cal_type'] ?? 0) == 0 && $sql) {
            DB::update(DB::raw($sql));
        }

        if ($address_id) {
            $this->orderRep->addOrderAddress($order['id'], $address_id);
        }

        return retSuc([
            'out_trade_no' => $order['out_trade_no'],
            'order_source' => $data['order_source']
        ]);
    }

    public function pay_param()
    {
        $order_id = intval(request()->get("order_id"));
        $member = $this->memberRep->getOne(UID);
        $order = $this->orderRep->getByOutTradeNo($order_id);

        if (!$order_id)
            return retFail("订单参数错误");

        if (!isset($order))
            return retFail("订单不存在");

        if ($order['uid'] != UID)
            return retFail("无权限");

        try {
            $wemch = Wemch::query()->where(['shop_id' => $order['shop_id'], 'status' => 1])->first();
            if ($wemch) {
                $config = [
                    'mch_id' => trim($wemch['mch_id']),
                    'mch_secret' => trim($wemch['secret']),
                ];
            } else {
                $config = null;
            }
            $wechatRep = new WechatRepository($config ?? null);

            $res = $wechatRep->unifiedOrder([
                'out_trade_no' => $order['out_trade_no'],
                'body' => "餐厅点餐",
                'openid' => $member['weapp_openid'],
                'total_price' => in_array(UID, [2, 107]) ? 0.01 : $order['total_price'],
            ]);

            return retSuc([
                'package' => $res['package'],
                'paySign' => $res['paySign'],
                'timeStamp' => strval(time()),
                'nonceStr' => $res['nonceStr'],
            ]);

        } catch (Exception $e) {
            return retFail($e->getMessage());
        }
    }

    /**
     * 详情
     * @Author   thomashtao               bosslen
     * @DateTime 2022-04-18T16:16:47+0800
     * @return   [type]                   [description]
     */
    public function detail()
    {
        $out_trade_no = trim(request()->GET("order_id"));
        if (!$out_trade_no)
            return retFail("参数错误");

        $order = $this->orderRep->getByOutTradeNo($out_trade_no);

        return retSuc(['order' => $order]);
    }

    /**
     * 分拣完成
     */
    public function deliver_list()
    {
        $filter = $this->_filter();
        empty($filter['status']) && $filter['status'] = 10;

        if ($filter['shop_type'] == 1) {
            if (empty($filter['shop_id'])) {
                return retFail("请先选择店铺");
            }

            if ($filter['shop_type'] == 1 && empty($filter['menu_id'])) {
                return retSuc([
                    "items" => [],
                    "total" => 0,
                    "current_page" => 1,
                    "last_page" => 1,
                ]);
            }

            $filter['shop_type'] = Supplier::query()->where(['id' => $filter['shop_id']])->value("type");
        } else {
            if ($filter['shop_id'] == -1) {
                $filter['shop_id'] = Supplier::query()->where(['type' => 0])->pluck('id')->toArray();
            }
        }

        $res = $this->orderRep->getOrderDliverList($filter, $this->pageNum, $this->pageSize);
        return retSuc($res);
    }

    /**
     * 分拣订单统计
     */
    public function deliver_stat()
    {
        $filter = $this->_filter();
        if ($filter['shop_id'] == -1) {
            $filter['shop_id'] = Supplier::query()->where(['type' => 0])->pluck('id')->toArray();
        }
        $res = $this->orderRep->getOrderDliverStat($filter);
        return retSuc($res);
    }

    //确认配送
    public function confirm_deliver()
    {
        $params = $this->_filter();
        if (empty($params['shop_id']))
            return retFail("请先选择店铺");

        if (!in_array($params['status'], [12, 16, 17]))
            return retFail("无操作权限");

        $params['uid'] = UID;
        return $this->orderRep->confirmDeliver($params);
    }

    /**
     * 取消订单
     */
    public function cancel()
    {
        $out_trade_no = request("order_id", 0);
        $reason = request()->post("reason", '');
        $original = request()->post("original", '');
        return $this->orderRep->cancelOrder($out_trade_no, $reason, $original ?? "");
    }

    /**
     * 查询条件
     */
    private function _filter()
    {
        $params = request()->all();
        $filter = [];

        if (!empty($params['printer_id'])) {
            $filter['printer_id'] = intval($params['printer_id']);
        }

        $m_filter['date'] = trim(str_replace(".", "-", $params['current_date']));
        if ($m_filter['date']) {
            $filter['menu_date'] = $filter['current_date'] = $m_filter['date'] = date("Y-m-d", strtotime($m_filter['date']));
        }
        if ($params['menu_type'] > 0) {
            $m_filter['type'] = intval($params['menu_type']) - 1;
        }

        if (strlen($params['shop_type']) > 0) {
            $filter['shop_type'] = intval($params['shop_type']);
        }

        if ($params['shop_id']) {
            $filter['shop_id'] = $m_filter['shop_id'] = intval($params['shop_id']);

            if ($params['shop_id'] > 0)
                $filter['shop_type'] = Supplier::query()->where("id", $filter['shop_id'])->value("type");
        }

        if ($filter['shop_type'] == 1) {
            $filter['menu_id'] = (new DailyMenuRepository())->getMenuIds($m_filter);
        }
        if ($params["ids"]) {
            if (is_array($params["ids"])) {
                $filter['ids'] = $params['ids'];
            } else {
                $filter['ids'] = array_filter(explode("-", $params["ids"]));
            }
        }
        if ($params['status']) {
            $filter['status'] = intval($params['status']);
        }

        !empty($params['printer_type']) && $filter['printer_type'] = $params['printer_type'];
        if (!empty($params['city_id'])) {
            $filter['city_id'] = json_decode($params['city_id'], true);
        }

        if (!empty($params['provinceIds'])) {
            $filter['provinceIds'] = json_decode($params['provinceIds'], true);
        }

        if (!empty($params['stat_city_ids'])) {
            $filter['stat_city_ids'] = $params['stat_city_ids'];
        }
        intval($params['deliver_time']) && $filter['deliver_time'] = $params['deliver_time'];

        return $filter;
    }

    public function delivery_time_list()
    {
        $shop_id = request()->get("shop_id", 0);
        $shop = (new ShopRepository())->getOne($shop_id);

        if (intval($shop['type']) != 0) {
            return retFail("非法请求");
        }

        //检查是否能看当天的
        if (count($shop['store_time']) == 2 && strtotime($shop['store_time'][1]) >= strtotime(date("H:i"))) {
            if ($shop) {
                $time = intval($shop['deliver_time']) + intval($shop['prepare_time']);

                if ($time > 0) {
                    $start_time = date("H:i", strtotime("+ $time minutes"));
                } else {
                    $start_time = date("H:i");
                }
            } else {
                $start_time = date("H:i");
            }

            //不能早于营业时间
            if (strtotime($start_time) < strtotime($shop['store_time'][0])) {
                $start_time = $shop['store_time'][0];
            }

            $todayRange = getDeliveryTimes($start_time, $shop['store_time'][1] ?? "");
            if ($todayRange) {
                $deliverDateList[] = [
                    'title' => "今天 (" . getWeek(date("Y-m-d")) . ')',
                    'date' => date("Y-m-d"),
                    'timeList' => $todayRange,
                ];
            }
        }

        $deliverDateList[] = [
            'title' => "明天 (" . getWeek(date("Y-m-d", strtotime("+1 day"))) . ')',
            'date' => date("Y-m-d", strtotime("+1 day")),
            'timeList' => getDeliveryTimes($shop['store_time'][0] ?? "", $shop['store_time'][1] ?? ""),
        ];

        return retSuc($deliverDateList);
    }

    /**
     * 打印初始化数据
     */
    public function printer_init_data()
    {
        $filter = $this->_filter();
        if ($filter['shop_type'] == 0 && $filter['menu_id']) {
            unset($filter['menu_id']);
        }

        if (!empty($filter['shop_id']) && $filter['shop_id'] == -1) {
//            unset($filter['shop_id']);
            return retFail("请选择店铺");
        }

        $printers = (new PrinterRepository())->getOptions(intval($filter['shop_id']), $filter['printer_type'] == 'label' ? 2 : 1);
        if ($filter['printer_type'] == 'label') { //品单
            $stalls = $this->orderRep->getOrderStalls($filter);
        }

        if ($filter['printer_type'] == 'stall') {
            $data = $this->orderRep->getOrderStallStat($filter);
            $total_product = array_sum(get_column($data, 'amount'));
            $orderIds = $this->orderRep->getOrderIdsByOrderProduct($filter);
            $total_order = count($orderIds);
        } else {
            $data = $this->orderRep->getOrderStat($filter);
            $total_product = array_sum(get_column($data, 'product_amount'));
            $total_order = array_sum(get_column($data, 'order_amount'));
        }

        return retSuc([
            'stalls' => $stalls ?? null,
            'printers' => $printers,
            'statList' => $data,
            'total_product' => $total_product ?? 0,
            'total_order' => $total_order ?? 0,
        ]);

    }

    /**
     * 打印数据
     */
    public function printer()
    {
        $params = request()->all();
        $printer_type = $params['printer_type'] ?? "";

        //判断是否有权限
        $printer = Printer::query()->where(['id' => intval($params['printer_id']), 'status' => 1])->first();
        if (empty($printer))
            return retFail("打印机不存在,请检查打印机是否设置");

        $filter = $this->_filter();
        /*if (empty($filter['stall_id'])) {
            $filter['stall_id'] = (new StallRepository())->getIdsByShopId(SHOP_ID);
        }*/
        if (!empty($filter['shop_id']) && $filter['shop_id'] == -1) {
            unset($filter['shop_id']);
        }

        if ($printer_type == 'label') { //标签打印
            return (new  PrinterRepository())->printerLabel($filter, intval($printer['id']));
        } else if ($printer_type == 'order') { //打印订单
            return $this->orderRep->printerOrder($filter, intval($printer['id']));
        } else if ($printer_type == 'stall') { //档口
            return $this->orderRep->printerStall($filter, intval($printer['id']));
        } else if ($printer_type == 'keshi') { //科室  ToDo : 待处理
//            $data =  $this->orderRep->getOrderStat($filter);
            return $this->orderRep->printerKs($filter, intval($printer['id']));

        } else {
            return retFail("打印类型不存在");
        }

    }

    public function export_order()
    {
        $filter = $this->_filter();
        $extra_conditions = [];
        if (isset($filter['between'])) {
            $extra_conditions['between'] = $filter['between'];
            unset($filter['between']);
        }
        /*if (!checkIsSuper(UID)) { //非系统管理员
            empty($filter['shop_id']) && $filter['shop_id'] = -1;
        }*/
        $orders = (new \App\Repositories\Manage\OrderRepository())->getList($filter, 1, 5000, $extra_conditions);

        // 导出excel
        $res = [];
        foreach ($orders['items'] as $k => $v) {
            $p_str = [];
            foreach ($v['products'] as $pk => $p) {

                if ($p['type'] == 2) {//多规格
                    $p_str[] = $p['title'] . ($p['sku_txt'] ? ('(' . $p['sku_txt'] . ')') : '') . ' x' . $p['amount'];
                } else if ($p['type'] == 1) { //套餐
                    $skus = [];
                    foreach ($p['skus'] as $sk => $sv) {
                        $skus[] = $sv['spec_item_title'] . 'x' . $sv['amount'];
                    }
                    $p_str[] = $p['title'] . ('(' . implode(',', $skus) . ')') . ' x' . $p['amount'];
                } else {
                    $p_str[] = $p['title'] . ' x' . $p['amount'];
                }
            }
            $d['out_trade_no'] = $v['out_trade_no'] . " ";
            $d['mobile'] = $v['address']['phone'] . " ";
            $d['create_time'] = $v['create_time'];
            $d['shop_title'] = $v['shop_title'];
            $d['menu_date'] = $v['delivery_date'];
            $d['menu_title'] = $v['menu_title'] ?? "";
            $d['deliver_time'] = $v['deliver_time'] ?? " "; //送达时间
            $d['current_status'] = order_filter_status($v['current_status']);
            $d['products'] = implode(", ", $p_str);
            $d['skus'] = "";
            $d['amount'] = $v['amount'];
            $d['total_price'] = $v['total_price'];
            $d['bag_price'] = $v['bag_price'];
            $d['express_price'] = $v['express_price'];
            $d['pay_time'] = date("Y-m-d H:i:s", $v['pay_time']);

            $d['refund_time'] = $v['refund_time'] ?? "";
            $d['refund_fee'] = $v['refund_price'];
            $d['remark'] = trim($v['remark'] ?? "");
            $d['address'] = $v['address']['province_title'] . ' ' .
                $v['address']['city_title'] . $v['address']['region_title'] . ' ' .
                $v['address_title']['district_title_title'] .
                $v['address']['address'] .
                $v['address']['consignee'];

            $res[] = $d;
        }

        $keys['out_trade_no'] = '订单号';
        $keys['phone'] = '手机号';
        $keys['create_time'] = '下单时间';
//        $keys['shop_type_title'] = '店铺类型';
        $keys['shop_title'] = '店铺';
        $keys['menu_date'] = '菜单时间';
        $keys['menu_title'] = '菜单餐段';

        $keys['deliver_time'] = '送达时间';
        $keys['current_status'] = '订单状态';
        $keys['products'] = '商品名称';
        $keys['skus'] = '规格/套餐';

        $keys['amount'] = '订单数量';
        $keys['total_price'] = '总金额';
        $keys['bag_price'] = '打包费';
        $keys['express_price'] = '配送费';
        $keys['pay_time'] = '支付时间';

        $keys['refund_time'] = '退款时间';
        $keys['refund_fee'] = '退款金额';
        $keys['remark'] = '客服备注';
        $keys['address'] = "收货信息";
        $keys['reason'] = "取消原因";

        return (new  ExportService())->store($res, $keys, "订单");
    }

    /**
     * 数据表格统计
     */
    public function stat_excel()
    {

    }
}
